from rest_framework.generics import ListAPIView, CreateAPIView
from rest_framework.viewsets import ModelViewSet, ReadOnlyModelViewSet

from apps.goods.models import SPU, SPUSpecification, Brand, GoodsCategory
from apps.meiduo_admin.serializers.spu import SpuModel, SPUViewSetModel, BrandSimpleSer, CategoriesSer
from apps.meiduo_admin.utils.MeiduoPage import PageNum


class SpuView(ListAPIView):
    queryset = SPU.objects.all()
    serializer_class = SpuModel


class SPUViewSet(ModelViewSet):
    queryset = SPU.objects.all()
    serializer_class = SPUViewSetModel
    pagination_class = PageNum


class BrandSimple(ListAPIView):
    queryset = Brand.objects.all()
    serializer_class = BrandSimpleSer


# 获取一级分类
class CategoriesViewSet(ListAPIView):
    # def get_queryset(self):
    queryset = GoodsCategory.objects.filter(parent_id__isnull=True)
    serializer_class = CategoriesSer


# 获取二级分类
class CategorieViewSet(ListAPIView):
    def get_queryset(self):
        pk = self.kwargs.get('pk')
        return GoodsCategory.objects.filter(parent_id=pk)

    serializer_class = CategoriesSer

# #保存
# class SPUCreate(CreateAPIView):
#     queryset = SPU.objects.all()
#     serializer_class =
